<style scoped>
  .text-align{
    text-align: center
  }
  .nickname{
    margin-left:10px;
    line-height: 3;
    font-size: 16px;
  }
  .createTime{
    margin-left:10px;
    line-height: 3;
    font-size: 16px;
  }
</style>
<template>
  <div>
    <div v-for="item in dataList" style="margin-top:5px">
      <el-row :gutter="20">
        <el-col :span="1" >
          <div class="grid-content text-align" >
             <div class="block"><el-avatar size="large" :src="item.avatar"></el-avatar></div>
          </div>
        </el-col>
        <el-col :span="10">
          <div class="grid-content nickname">
            <span v-text="item.nickname"></span>
          </div>
        </el-col>
        <el-col :span="13">
          <div class="grid-content nickname" style="text-align: right">
            <span v-text="item.createTime"></span>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="grid-content">
            <el-rate
              v-model="item.commentLevel"
              disabled
              show-score
              text-color="#ff9900"
              score-template="{value}">
            </el-rate>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="grid-content nickname">
            他/她说：<span v-text="item.content" ></span>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="4" :offset="20">
          <div class="grid-content nickname " style="text-align: center">
            <el-button type="primary" @click="deleteHandle(item.id)">删除</el-button>
          </div>
        </el-col>
      </el-row>
      <el-divider></el-divider>
    </div>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    name: "user-comment",
    methods: {
      //评论列表
      commentList(targetUserId) {
        this.userId=targetUserId;
        this.$http({
          url: this.$http.adornUrl('/simida/usermakecomment/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'targetUserId': targetUserId,
          }, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list;
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = [];
            this.totalPage = 0;
          }
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm(`确定对[id=${id}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/simida/usermakecomment/delete/'+id),
            method: 'delete',
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.commentList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.commentList(this.userId)
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.commentList(this.userId)
      },

    },
    data() {
      return {
        userId:0,
        dataForm: {
          targetUserId: '',
        },
        dataList:[],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
      }
    }
  }
</script>

